package com.sushe.service;

import com.sushe.dao.BedDao;
import com.sushe.dao.RoomDao;
import com.sushe.dao.StudentDao;
import com.sushe.service.jiekou.RoomQueryService;

import java.sql.SQLException;
import java.util.Scanner;

public class RoomQueryServiceImpl implements RoomQueryService {

    private StudentDao studentDao = new StudentDao();
    private RoomDao roomDao = new RoomDao();
    private BedDao bedDao = new BedDao();


    @Override
    public  void queryRoomByStudent() throws SQLException, ClassNotFoundException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入想要查询的学生姓名：");
        String studentName = sc.nextLine();
        //根据学生姓名获取学生ID
        Integer studentId = studentDao.getStudentId(studentName);
        //在bed表中查询该学生的room_id
        Integer roomId= bedDao.getRoomIdByStudentId(studentId);
        if(roomId==null){
            System.out.println("该学生没有入住宿舍!");
            return;
        }
        System.out.println("该学生的宿舍楼为："+bedDao.getBuildingNameByRoomId(roomId));
        System.out.println("该学生的宿舍房间号为："+ roomDao.getRoomNumberByRoomId(roomId));
    }
}
